###########################################################################
#
# File:         SConstruct (directory: ./)
# Date:         1-Oct-2007
# Author:       Hugh Secker-Walker
# Description:  Top-level SConstruct, sets up SCons environments, calls ./SConscript
#
# This file is part of Onyx   http://onyxtools.sourceforge.net
#
# Copyright 2007 - 2009 The Johns Hopkins University
#
# Licensed under the Apache License, Version 2.0 (the "License").
# You may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#   http://www.apache.org/licenses/LICENSE-2.0
# 
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.  See the License for the specific language governing
# permissions and limitations under the License.
#
###########################################################################

# show the default environment
#print
#print Environment().Dump()

# top-level SConscript that dispatches to directory-specific SConscript files
top_level_sconscript = './SConscript'

# set up command-line variables
vars = Variables()

# this default build-top must be used when making logref reference log files
BUILD_TOP_DEFAULT = 'build'
vars.Add(PathVariable('BUILD_TOP',
                      'Name of subdirectory, relative to the project, under '
                      'which the platform-specific build should occur',
                      BUILD_TOP_DEFAULT,
                      PathVariable.PathAccept))

vars.Add(BoolVariable('NO_DOC',
                      'Set to True to skip documentation building',
                      False))

if vars.UnknownVariables():
    raise ValueError("unhandled command-line variables: %s" % ' '.join(sorted(vars.UnknownVariables())))

# show the environment with variables loaded
## env0 = Environment(tools=[], variables=vars)
## print
## print env0.Dump()
## del env0

# mechanism to override default tools
# XXX really need to have separate builds that all get done, e.g. with
# multiple environments

# SCons tools that we use
tools = (

    # note: we are relying on SCons to implement that the order in
    # which the tools get generated (initialized) to be the same as
    # the order here; the Onyx tool sets up construction variables
    # in the env that PyTools relies upon; to date (11/2007) SCons
    # has behaved the way we need

    # SCons default and/or other built-in tools first; that way, the 
    # items we prepend to PATH etc when our tools are loaded come
    # before the default items
    'default',

    # ProjectTools sets up project-level entities in the env
    'ProjectTools',
    
    # PyTools is a set of Scons tools for Python files
    'PyTools',
    )

# note: the Onyx and PyTools tool that we ask for set up some Onyx-specific
# stuff in the environment, and they use the vars we've just set up, see
# site_scons/site_tools/Onyx.py and site_scons/site_tools/PyTools.py
import os
env = Environment(tools=tools, 
                  variables=vars,
                  ENV={'PATH':os.environ['PATH'], 
                       'HOME':os.environ['HOME']},
                  CPPFLAGS='$CPPFLAGS -Wall -Werror')

# print env['ENV']['PATH']

# generate help for command-line variables
Help(vars.GenerateHelpText(env))

Export('env')

# for debugging, show the environment we've created
if False:
    print
    print env.Dump()
    print
    print dir(env)
    print
    print dir()
    print

# call the top-level SConscript file
env.SConscript([top_level_sconscript],
               build_dir=env['ONYX_BUILD'],
               duplicate=1)

# meta-work 
env.ManagedFiles('managed_file_list.txt')
env.DocTestSummary()
